<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Api\Controllers\Auths;

use App\Api\BaseApi;
use App\Models\ProductOrder;

class OrderApi extends BaseApi
{
    public function getProductOrder()
    {
        $request = self::validate([
            'status' => 'required',
        ]);
        $status = $request->get('status');
        if ($status == 0) {
            $order = ProductOrder::with(['productBrief', 'Shipment'])
                ->where('user_id', self::UserId())
                ->simplePaginate($request->get('pageSize', 10));
        } else {
            $order = ProductOrder::with(['productBrief'])
                ->whereHas('Shipment', function ($query) {
                    $query->where('status', 0);
                })
                ->where('status', $status)
                ->where('user_id', self::UserId())
                ->simplePaginate($request->get('pageSize', 10));
        }
        return responses($order);
    }

    public function getProductOrderDetails()
    {
        $request = self::validate([
            'id' => 'required',
        ]);
        $order = ProductOrder::with(['productBrief', 'Shipment'])
            ->where('user_id', self::UserId())
            ->find($request->get('id'));
        return responses($order);
    }
}
